<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/19
 * Time: 19:43
 */

namespace app\api\controller;


use app\common\controller\ReturnCode;
use think\Controller;
use think\Request;
use app\api\model\Order as OD;
class Order extends Controller
{
    function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this -> openId = $request -> param('openid');
    }

    //列表
    public function index(){
        if(empty($this -> openId)){
            return json(['code'=>2,'msg'=>ReturnCode::$return_code[2]]);
        }
        $res = OD::where('openid','=',$this -> openId)->select();
        foreach ($res as $key => $val){
            if($val['order_spec']){
            $arr = object_array(json_decode($val['order_spec']));
            print_r($arr);

                foreach ($arr as $k => $v){
//                    dump($v);
                    foreach ($v as $item => $value){
//                        dump($value);
                        if($item == 'spec'){
                            foreach ($value as $it => $va){
//                                dump($va);
//                                foreach ($va as $i => $e){
//                                    dump($i);
                                    $d = db('set_'.$it)->where($it.'_id','=',$va)->find();
//                                    $va[$i] = $d[$i.'_name'];
//                                }
//                                dump($va);
//                                $value[$it] = implode(',',$va);
                                $value[$it] = $d[$it.'_name'];
                            }
                            $v[$item] = $value;
                        }
//                        dump($v);
                    }
                    $arr[$k] = $v;
                }
//                dump($arr);
                $val['order_spec'] = $arr;
                $res[$key] = $val;
            }
        }

        if($res){
            return json(['code'=>0,'msg'=>ReturnCode::$return_code[0],'data'=>$res]);
        }
        return json(['code'=>10,'msg'=>ReturnCode::$return_code[10]]);
    }

    //订单详情
//    public function orderinfo(){
//
//    }
}